﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using EQT.Bll;
using EQT.Model;
using EQT.Dal;
using System.Collections.Generic;

public class UploadDoc : IUploadFile
{

    private DaTfile datfile;

    public UploadDoc()
    {
        datfile = new DaTfile(DaCommon.DefaultDb);
    }


    #region IUploadFile 成员

    public void InitUpload(IUploadPage up, System.Collections.Specialized.NameValueCollection nvc)
    {

        up.SetConfigValue("UPLOAD_MODE", nvc[null]);

        string dirid = nvc["dirid"];
        if (String.IsNullOrEmpty(dirid) || dirid.Trim().Length == 0)
        {
            Utility.SiteError("缺失所必需的参数【目录编号】", up.Response);
            return;
        }
        else
        {
            up.SetConfigValue("DIRID", dirid.Trim());
        }
        string dirname = up.Server.HtmlDecode(nvc["dirname"]);
        if (String.IsNullOrEmpty(dirname) || dirname.Trim().Length == 0)
        {
            Utility.SiteError("缺失所必需的参数【目录名称】", up.Response);
            return;
        }
        else
        {
            up.SetConfigValue("DIRNAME", dirname);
        }
        up.SetPageTitle(String.Format("在目录【{0}】，编号【{1}】下添加文件：", dirname, dirid));
    }

    public int Upload1(IUploadPage up, MoTfile file, string opter_id)
    {
        #region 为文档管理而上传
        MoDirFile modf = new MoDirFile();
        modf.Df_Id = file.File_Id;
        modf.Df_Name = file.File_Name;
        modf.Df_Flag = "F";
        modf.Parent_Did = up.GetConfigValue("DIRID").ToString();
        try
        {
            return datfile.AddFileEx(modf, file);
        }
        catch (DalException de)
        {
            Utility.GlobalLog.Error("添加单个文件失败!", de);
            Utility.SiteError("添加单个文件失败!" + de.Message, up.Response);
            return -1;
        }
        #endregion
    }

    public int UploadedMuliti(IUploadPage up, List<MoTfile> files, string opter_id)
    {
        throw new Exception("The method or operation is not implemented.");
    }

    public string GetReturnUrl(IUploadPage up)
    {
        return String.Format("docs.aspx?dir_id={0}", up.GetConfigValue("DIRID"));
    }

    #endregion
}